package com.heima.article.listener;


import com.alibaba.fastjson.JSON;
import com.heima.article.service.ApArticleConfigService;
import com.heima.common.constants.WmNewsMessageConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.Map;

@Component
public class EnableListener {

    @Autowired
    private ApArticleConfigService apArticleConfigService;

    @KafkaListener(topics = WmNewsMessageConstants.WM_NEWS_UP_OR_DOWN_TOPIC)
    public void onMsg(String msg){
        if(!StringUtils.isEmpty(msg)){
            System.out.println("获取到需要操作的数据json："+msg);
            // 上下架业务
            Map map = JSON.parseObject(msg, Map.class);
            //
            apArticleConfigService.updateByIsDown(map);
            //
            System.out.println("文章修改完成");

        }
    }
}
